package com.yanggu.flink.datastream_api.source

import org.apache.flink.streaming.api.scala._

/**
 * 从文件读取数据
 */
object SourceFromFile {

  def main(args: Array[String]): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)

    //hello.txt需要放在resources目录下
    val stream = env.readTextFile(getClass.getResource("/hello.txt").getPath)
    val value = stream
      .flatMap(_.split(" "))
      .filter(_.nonEmpty)
      .map((_, 1))
      .keyBy(_._1)
      .sum(1)

    value.print("stream1: ")
      .setParallelism(1)

    env.execute()
  }

}
